$("body").keyup(function (event) {
    if (event.keyCode == "13") {
        $("#signin").click();
    }
});

$("#signin").click(function () {
    var name = $('#name').val();
    var account = $('#account').val();
    var psw1 = $('#psw1').val();
    var psw2 = $('#psw2').val();
    var character = $("input[name = 'character']:checked").val();

    if (name == '') {
        alert('请输入用户名');
        location.reload();
        return false;
    }
    if (account == '') {
        alert('请输入用户名');
        location.reload();
        return false;
    }
    if (psw1 == '') {
        alert('请输入密码');
        location.reload();
        return false;
    }
    if (psw2 == '') {
        alert('请重复密码');
        location.reload();
        return false;
    }
    if (psw1 != psw2) {
        alert('两次密码不一致！')
        location.reload();
        return false;
    }
    if (character == null) {
        alert('请选择账户类别');
        location.reload();
        return false;
    }
//将数据传到后台
    $.ajax({
        url: '/user?method=signIn',
        type: 'post',
        data: {account: account, psw: psw1, character: character, name: name},
        dataType: 'json',
        success: function (result) {
            if (result) {
                alert('注册成功');
                location.reload();
                location.href = "login.html";
            }
            else {
                alert('失败，用户名已存在');
                location.reload();
            }
        }
    });
});